package com.example.mapp;

import com.example.entity.*;
import com.example.ext.entity.ExtElevator;
import com.example.mapp.buildSql.ElevatorMappSql;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by youkun on 2017/9/22.
 */
@Mapper
public interface ElevatorMapp {

    @Select( " select a.*,e.user_name as safeUserName,b.type_name as elevatorTypeName, c.party_name as usedPartyName, c.credit_code as creditCode," +
            "d.party_name as maintenancePartyName, f.check_end_dt as checkEndDt" +
            " from elevator a " +
            "left join elevator_type b on a.elevator_type_id = b.id  " +
            "left join party c on c.id = a.used_party_id  " +
            "left join party d on d.id = a.maintenance_party_id " +
            "left join daily_inspection f on f.elevator_id=a.id " +
            "left join sys_user e on a.safe_user_id = e.id "+
            " where a.id=#{id} " +
            " ORDER BY f.id desc limit 1 " )
    ExtElevator queryById(String id) throws Exception;

    @SelectProvider(type = ElevatorMappSql.class,method = "queryElevatorListByExtElevator")
    List<ExtElevator>queryElevatorList(ExtElevator extElevator) throws Exception;
    @SelectProvider(type = ElevatorMappSql.class,method = "queryMainParty")
    List<Map<String,String>> queryMainParty(ExtElevator extElevator) throws Exception;
    @SelectProvider(type = ElevatorMappSql.class,method = "queryUsedParty")
    List<Map<String,String>> queryUsedParty(ExtElevator extElevator) throws Exception;
    @SelectProvider(type = ElevatorMappSql.class,method = "queryProgramName")
    List<String>queryProgramName(ExtElevator extElevator) throws Exception;
    @SelectProvider(type = ElevatorMappSql.class,method = "queryList")
    List<ExtElevator> queryList(ExtElevator elevator) throws Exception;

    @SelectProvider(type = ElevatorMappSql.class,method = "queryMaintList")
    List<ExtElevator> queryMaintList(Map<String, Object> elevator) throws Exception;

    @SelectProvider(type = ElevatorMappSql.class,method = "queryJgList")
    List<ExtElevator> queryJgList(Map<String, Object> elevator) throws Exception;



    @Select("select * from elevator where elevator_num=#{elevatorNum}")
    Elevator queryByElevatorNum(String elevatorNum) throws Exception;

    @Insert("insert into elevator ( angle, be_used_date, " +
            "      build_addr, build_party_name, building_info, " +
            "      create_company_name, drive_way, elevator_addr, " +
            "      elevator_area, elevator_building_num, elevator_city, " +
            "      elevator_model, elevator_num, elevator_photo_url, " +
            "      elevator_province, elevator_street, elevator_type_id, " +
            "      examination_party_id, examination_party_name, " +
            "      floor_station, governor_ck_date, insurance_date, " +
            "      insurance_name, insurance_num, is_stop, " +
            "      last_maintenance_time, lift_height, maint_tel, " +
            "      maintenance_party_id, maintenance_user_first, " +
            "      maintenance_user_second, next_check_date, next_halfmon_maint_date, " +
            "      next_halfyear_maint_date, next_quarterly_mainte_date, " +
            "      next_year_maint_date, outside_num, points_num, " +
            "      qr_code_url, rated_load, rescue_phone_num, " +
            "      run_speed, safe_user_id, safe_user_tel, " +
            "      serial_num, step_width, url, " +
            "      used_num, used_party_id,brand_Name,branch_office,place_type,elevator_place,"
            + "    examination_user_first,examination_user_second,inner_id,last_inspect_date,program_name)" +
            "    values ( #{angle}, #{beUsedDate}, " +
            "      #{buildAddr}, #{buildPartyName}, #{buildingInfo}, " +
            "      #{createCompanyName}, #{driveWay}, #{elevatorAddr}, " +
            "      #{elevatorArea}, #{elevatorBuildingNum}, #{elevatorCity}, " +
            "      #{elevatorModel}, #{elevatorNum}, #{elevatorPhotoUrl}, " +
            "      #{elevatorProvince}, #{elevatorStreet}, #{elevatorTypeId}, " +
            "      #{examinationPartyId}, #{examinationPartyName}, " +
            "      #{floorStation}, #{governorCkDate}, #{insuranceDate}, " +
            "      #{insuranceName}, #{insuranceNum}, #{isStop}, " +
            "      #{lastMaintenanceTime}, #{liftHeight}, #{maintTel}, " +
            "      #{maintenancePartyId}, #{maintenanceUserFirst}, " +
            "      #{maintenanceUserSecond}, #{nextCheckDate}, #{nextHalfmonMaintDate}, " +
            "      #{nextHalfyearMaintDate}, #{nextQuarterlyMainteDate}, " +
            "      #{nextYearMaintDate}, #{outsideNum}, #{pointsNum}, " +
            "      #{qrCodeUrl}, #{ratedLoad}, #{rescuePhoneNum}, " +
            "      #{runSpeed}, #{safeUserId}, #{safeUserTel}, " +
            "      #{serialNum}, #{stepWidth}, #{url}, " +
            "      #{usedNum}, #{usedPartyId},#{brandName},#{branchOffice},#{placeType},#{elevatorPlace},"
            + "    #{examinationUserFirst},#{examinationUserSecond},#{innerId},#{lastInspectDate},#{programName})")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    int add(Elevator elevator) throws Exception;

    @Update("update  elevator set angle=#{angle}, be_used_date=#{beUsedDate},  " +
            "      build_addr=#{buildAddr}, build_party_name=#{buildPartyName}, building_info=#{buildingInfo}, " +
            "      create_company_name=#{createCompanyName}, drive_way=#{driveWay}, elevator_addr=#{elevatorAddr}, " +
            "      elevator_area=#{elevatorArea}, elevator_building_num=#{elevatorBuildingNum}, elevator_city=#{elevatorCity}, " +
            "      elevator_model=#{elevatorModel}, elevator_num=#{elevatorNum}, elevator_photo_url=#{elevatorPhotoUrl}, " +
            "      elevator_province=#{elevatorProvince}, elevator_street=#{elevatorStreet}, elevator_type_id=#{elevatorTypeId}, " +
            "      examination_party_id=#{examinationPartyId}, examination_party_name=#{examinationPartyName}, " +
            "      floor_station=#{floorStation}, governor_ck_date =#{governorCkDate}, insurance_date=#{insuranceDate}, " +
            "      insurance_name=#{insuranceName}, insurance_num=#{insuranceNum}, is_stop=#{isStop}, " +
            "      last_maintenance_time=#{lastMaintenanceTime}, lift_height=#{liftHeight}, maint_tel=#{maintTel}, " +
            "      maintenance_party_id=#{maintenancePartyId}, maintenance_user_first=#{maintenanceUserFirst}, " +
            "      maintenance_user_second=#{maintenanceUserSecond}, next_check_date=#{nextCheckDate}, next_halfmon_maint_date=#{nextHalfmonMaintDate}, " +
            "      next_halfyear_maint_date=#{nextHalfyearMaintDate}, next_quarterly_mainte_date=#{nextQuarterlyMainteDate}, " +
            "      next_year_maint_date=#{nextYearMaintDate}, outside_num=#{outsideNum}, points_num=#{pointsNum}, " +
            "      qr_code_url=#{qrCodeUrl}, rated_load=#{ratedLoad}, rescue_phone_num=#{rescuePhoneNum}, " +
            "      run_speed=#{runSpeed}, safe_user_id=#{safeUserId}, safe_user_tel=#{safeUserTel}, " +
            "      serial_num=#{serialNum}, step_width=#{stepWidth}, url=#{url}, " +
            "      used_num=#{usedNum}, used_party_id=#{usedPartyId},brand_Name=#{brandName},"
            + "    branch_office=#{branchOffice},place_type=#{placeType}, elevator_place=#{elevatorPlace},examination_user_first=#{examinationUserFirst},examination_user_second=#{examinationUserSecond},"
            + "    inner_id=#{innerId},last_inspect_date=#{lastInspectDate},program_name=#{programName},branch_office = #{branchOffice} where id=#{id}")
    int update(Elevator elevator) throws Exception;

    @Delete("delete from elevator where id=#{id}")
    int deleteById(String id) throws Exception;

    @Update("update elevator set maintenance_party_id = null where id = #{id}")
    void batchDelete(String id);

    @Update("update elevator a set last_maintenance_time=#{lastMaintenanceTime},next_halfmon_maint_date=#{nextHalfmonMaintDate} where elevator_num=#{elevatorNum}")
    int updatehmMaintDate(Map inMap) throws Exception;

    @Update("update elevator a set last_maintenance_time=#{lastMaintenanceTime},next_quarterly_mainte_date=#{nextQuarterlyMainteDate} where elevator_num=#{elevatorNum}")
    int updateqMaintDate(Map inMap) throws Exception;

    @Update("update elevator a set last_maintenance_time=#{lastMaintenanceTime},next_halfyear_maint_date=#{nextHalfyearMaintDate} where elevator_num=#{elevatorNum}")
    int updatehyMaintDate(Map inMap) throws Exception;

    @Update("update elevator a set last_maintenance_time=#{lastMaintenanceTime},next_year_maint_date=#{nextYearMaintDate} where elevator_num=#{elevatorNum}")
    int updateyMaintDate(Map inMap) throws Exception;

    @Update("update elevator set points_num=points_num+1 where id=#{id}")
    int updateLikeNum(String id) throws Exception;

    @Update("update elevator set lat=#{lat}, lng=#{lng} where id=#{id}")
    int updateLatLng(Map inmap) throws Exception;

    @Update("update elevator set place_type=#{placeType}, elevator_place=#{elevatorPlace} where id=#{id}")
    int updateElevatorPlace(Map inmap) throws Exception;

    @Select("select * from elevator where used_party_id = #{usedPartyId}")
    List<Elevator> queryByUsedPartyId(String usedPartyId) throws Exception;

    @SelectProvider(type = ElevatorMappSql.class,method = "getLatLng")
    List<Map> getLatLng(Map inmap,String mark) throws Exception;

    @SelectProvider(type = ElevatorMappSql.class,method = "updateSafeUser")
    Integer updateSafeUser(Map inMap) throws  Exception;

    @Select("select * from elevator where elevator_num = #{elevatorNum}")
    ExtElevator getElevatorInfoByNum(Map map) throws Exception;

    @Update("update elevator set mark=#{mark} where id=#{id}")
    int updateMark(Elevator elevator);

    @Update("update elevator set technique_mark=#{techniqueMark} where id=#{id}")
    int updateTechniqueMark(Elevator elevator);

    @UpdateProvider(type = ElevatorMappSql.class,method = "updateProjectName")
    int updateProjectName(Map map);

    @Select("select sum(ifnull(mark,0)) as mark  from elevator where  used_party_id=#{partyId} ")
    Map getSumMark(String partyId);

    @Select("select sum(ifnull(technique_mark,0)) as techniqueMark  from elevator where  used_party_id=#{partyId} ")
    Map getSumTechniqueMark(String partyId);
    // 双随机一公开查询电梯信息
    @SelectProvider(type = ElevatorMappSql.class,method = "getElevatorList")
    List<Map<String, Object>> getElevatorList(Map<String, Object> param);

    @SelectProvider(type = ElevatorMappSql.class,method = "detectionGetElevator")
    List<Map<String,Object>> detectionGetElevator(Map<String, Object> param);

    /**
     * 按需维保查询电梯信息
     * @param elevator
     * @return
     */
    @SelectProvider(type = ElevatorMappSql.class,method = "queryElevatorList")
    List<ExtElevator> demandMaintGetElevators(ExtElevator elevator) throws Exception;

    /**
     * 按需维保查询某使用单位、或者维保单位下所有台账对应的制造单位
     */
    @SelectProvider(type = ElevatorMappSql.class,method = "getElevatorCreateComanys")
    List<String> queryCreateCompanys(ExtElevator elevator) throws Exception;

    /**
     * 按需维保更新电梯是否参与维保与维保变更天数
     * @param inMap
     * @return
     * @throws Exception
     */
    @UpdateProvider(type = ElevatorMappSql.class,method = "elevatorDemandMaintanceDay")
    int updateElevatorDemandMaintanceDay(Map inMap) throws Exception;

    /**
     * 无纸化维保查询电梯信息
     * @param elevator
     * @return
     * @throws Exception
     */
    @SelectProvider(type = ElevatorMappSql.class , method = "queryPaperlessElevatorList")
    List<ExtElevator> paperlessMaintGetElevators(ExtElevator elevator) throws Exception;

    /**
     * 无纸化维保更新电梯参与无纸化维保标识
     * @param map
     * @return
     * @throws Exception
     */
    @UpdateProvider(type = ElevatorMappSql.class , method = "updatePaperLessElevators")
    int updatePaperLessElevators(Map map) throws  Exception;

    /**
     * 与和苏进行对接接口，新增电梯台账信息
     * @param list
     */
    @Insert("<script> insert into elevator (angle,be_used_date,brand_name, " +

            "      build_addr, build_party_name, building_info, " +
            "      create_company_name, drive_way, elevator_addr, " +
            "      elevator_area, elevator_building_num, elevator_city, " +
            "      elevator_model, elevator_num, elevator_photo_url, " +
            "      elevator_province, elevator_street, elevator_type_id, " +
            "      examination_party_id, examination_party_name, " +
            "      floor_station, governor_ck_date, insurance_date, " +
            "      insurance_name, insurance_num, is_stop, " +
            "      last_maintenance_time, lat,lift_height, lng,maint_tel, " +
            "      maintenance_party_id, maintenance_user_first, " +
            "      maintenance_user_second, next_check_date, next_halfmon_maint_date, " +
            "      next_halfyear_maint_date, next_quarterly_mainte_date, " +
            "      next_year_maint_date, outside_num, points_num, " +
            "      qr_code_url, rated_load, rescue_phone_num, " +
            "      run_speed, safe_user_id, safe_user_tel, " +
            "      serial_num, step_width, url, " +
            "      used_num, used_party_id,branch_office,elevator_place,"
            + "    examination_user_first,examination_user_second,inner_id,last_inspect_date,place_type,program_name,last_maintenance_party_name, " +
            "      make_date,mark,technique_mark,is_participate_in,maintenance_day,maintenance_party_credit_code,used_party_credit_code,check_qualified_photo," +
            "      elevator_type_name,used_party_name,safe_user_name,maintenance_user_first_name,maintenance_user_second_name," +
            "      examination_user_first_name,examination_user_second_name,create_by,out_elevator_id,create_date,maintenance_party_name )" +
            "    values " +
            "<foreach collection = 'list' item='record' separator=',' > "+
            "      ( #{record.angle},#{record.beUsedDate},#{record.brandName}, " +
            "      #{record.buildAddr},#{record.buildPartyName},#{record.buildingInfo}, " +
            "      #{record.createCompanyName},#{record.driveWay},#{record.elevatorAddr}, " +
            "      #{record.elevatorArea},#{record.elevatorBuildingNum},#{record.elevatorCity}, " +
            "      #{record.elevatorModel}, #{record.elevatorNum}, #{record.elevatorPhotoUrl}, " +
            "      #{record.elevatorProvince}, #{record.elevatorStreet}, #{record.elevatorTypeId}, " +
            "      #{record.examinationPartyId}, #{record.examinationPartyName}, " +
            "      #{record.floorStation}, #{record.governorCkDate}, #{record.insuranceDate}, " +
            "      #{record.insuranceName}, #{record.insuranceNum}, #{record.isStop}, " +
            "      #{record.lastMaintenanceTime},#{record.lat}, #{record.liftHeight},#{record.lng}, #{record.maintTel}, " +
            "      #{record.maintenancePartyId}, #{record.maintenanceUserFirst}, " +
            "      #{record.maintenanceUserSecond}, #{record.nextCheckDate}, #{record.nextHalfmonMaintDate}, " +
            "      #{record.nextHalfyearMaintDate}, #{record.nextQuarterlyMainteDate}, " +
            "      #{record.nextYearMaintDate}, #{record.outsideNum}, #{record.pointsNum}, " +
            "      #{record.qrCodeUrl}, #{record.ratedLoad}, #{record.rescuePhoneNum}, " +
            "      #{record.runSpeed}, #{record.safeUserId}, #{record.safeUserTel}, " +
            "      #{record.serialNum}, #{record.stepWidth}, #{record.url}, " +
            "      #{record.usedNum}, #{record.usedPartyId},#{record.branchOffice},#{record.elevatorPlace},"
            + "    #{record.examinationUserFirst},#{record.examinationUserSecond},#{record.innerId},#{record.lastInspectDate},#{record.placeType},#{record.programName}," +
            "      #{record.lastMaintenancePartyName},#{record.makeDate},#{record.mark},#{record.techniqueMark},#{record.isParticipateIn},#{record.maintenanceDay}," +
            "      #{record.maintenancePartyCreditCode},#{record.usedPartyCreditCode},#{record.checkQualifiedPhoto},#{record.elevatorTypeName}," +
            "      #{record.usedPartyName},#{record.safeUserName},#{record.maintenanceUserFirstName},#{record.maintenanceUserSecondName}," +
            "      #{record.examinationUserFirstName},#{record.examinationUserSecondName},#{record.createBy},#{record.outElevatorId},#{record.createDate},#{record.maintenancePartyName}  )"
            + "</foreach>"
            + "</script>")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    void interfaceAdd(List<Map<String, Object>> list);


    /**
     * 查询电梯表数据
     * @return
     */
    @Select(" SELECT id as 'id', " +
            " elevator_num AS 'elevatorNum', " +
            " outside_num AS 'outsideNum', " +
            " serial_num AS 'serialNum', " +
            " elevator_province AS 'elevatorProvince', " +
            " elevator_city AS 'elevatorCity', " +
            " elevator_area AS 'elevatorArea', " +
            " elevator_street AS 'elevatorStreet', " +
            " elevator_addr AS 'elevatorAddr', " +
            " elevator_model AS 'elevatorModel', " +
            " elevator_type_name AS 'elevatorTypeName', " +
            " maintenance_party_name AS 'maintenancePartyName', " +
            " maintenance_party_credit_code AS 'maintenancePartyCreditCode', " +
            " used_party_name AS 'usedPartyName', " +
            " used_party_credit_code AS 'usedPartyCreditCode', " +
            " elevator_building_num AS 'elevatorBuildingNum', " +
            " create_company_name AS 'createCompanyName', " +
            " examination_party_name AS 'examinationPartyName', " +
            " next_check_date AS 'nextCheckDate', " +
            " check_qualified_photo AS 'checkQualifiedPhoto', " +
            " safe_user_name AS 'safeUserName', " +
            " maintenance_user_first_name AS 'maintenanceUserFirstName', " +
            " maintenance_user_second_name AS 'maintenanceUserSecondName', " +
            " rescue_phone_num AS 'rescuePhoneNum', " +
            " is_stop AS 'isStop', " +
            " brand_name AS 'brandName', " +
            " maint_tel AS 'maintTel', " +
            " insurance_name AS 'insuranceName', " +
            " insurance_date AS 'insuranceDate', " +
            " build_addr AS 'buildAddr', " +
            " used_num AS 'usedNum', " +
            " be_used_date AS 'beUsedDate', " +
            " governor_ck_date AS 'governorCkDate', " +
            " floor_station AS 'floorStation', " +
            " safe_user_tel AS 'safeUserTel', " +
            " build_party_name AS 'buildPartyName', " +
            " rated_load AS 'ratedLoad', " +
            " run_speed AS 'runSpeed', " +
            " angle AS 'angle', " +
            " step_width AS 'stepWidth', " +
            " lift_height AS 'liftHeight', " +
            " drive_way AS 'driveWay', " +
            " lat AS 'lat', " +
            " lng AS 'lng', " +
            " branch_office_name AS 'branchOfficeName', " +
            " elevator_place AS 'elevatorPlace', " +
            " out_elevator_id AS 'outElevatorId', " +
            " maintenance_party_id AS 'maintenancePartyId', " +
            " used_party_id AS 'usedPartyId', " +
            " elevator_type_id AS 'elevatorTypeId' " +
            " FROM elevator where out_elevator_id=#{outElevatorId} and  elevator_num is not null  limit 1")
    ReceiveHesuElevator interfaceFindData(String outElevatorId);


    @Update(" update elevator set outside_num=#{outsideNum},"+
            "  serial_num=#{serialNum},elevator_province=#{elevatorProvince},elevator_city=#{elevatorCity}," +
            "  elevator_area=#{elevatorArea},elevator_street=#{elevatorStreet},elevator_addr=#{elevatorAddr},"+
            "  elevator_model =#{elevatorModel},elevator_type_name=#{elevatorTypeName}," +
            "  maintenance_party_name=#{maintenancePartyName},maintenance_party_credit_code=#{maintenancePartyCreditCode},"+
            "  used_party_name=#{usedPartyName},used_party_credit_code=#{usedPartyCreditCode},elevator_building_num=#{elevatorBuildingNum}," +
            "  create_company_name=#{createCompanyName},examination_party_name=#{examinationPartyName},next_check_date=#{nextCheckDate}," +
            "  check_qualified_photo=#{checkQualifiedPhoto},safe_user_name=#{safeUserName},maintenance_user_first_name=#{maintenanceUserFirstName},"+
            "  maintenance_user_second_name=#{maintenanceUserSecondName},rescue_phone_num=#{rescuePhoneNum},is_stop=#{isStop}," +
            "  brand_name=#{brandName},maint_tel=#{maintTel},insurance_name=#{insuranceName},"+
            "  insurance_date=#{insuranceDate},build_addr=#{buildAddr},used_num=#{usedNum}," +
            "  be_used_date=#{beUsedDate},governor_ck_date=#{governorCkDate},floor_station=#{floorStation}," +
            "  safe_user_tel=#{safeUserTel},build_party_name=#{buildPartyName},"+
            "  rated_load=#{ratedLoad},run_speed=#{runSpeed},angle=#{angle},step_width=#{stepWidth}," +
            "  lift_height=#{liftHeight},drive_way=#{driveWay},lat=#{lat},lng=#{lng},branch_office_name=#{branchOfficeName}," +
            "  elevator_place=#{elevatorPlace},create_date=#{createDate} where out_elevator_id=#{outElevatorId}")
    void interfaceUpdate(Map map);

    /**
     * 更新电梯台账的保险单位记录
     * @param param
     * @return
     * @throws Exception
     */
    @UpdateProvider(type = ElevatorMappSql.class,method = "updateInstanceDate")
    int updateInstanceDate(Map<String,Object> param) throws Exception;

    /**
     * 通过外部关联码来查询数据
     * @param emergencyRescue
     * @return
     */
    @Select("select * from elevator where out_elevator_id = #{outElevatorId}")
    Elevator elevatorByOutId(EmergencyRescue emergencyRescue);

    @SelectProvider(type = ElevatorMappSql.class,method = "updateChessboard")
    void updateChessboard(Map<String, Object> param);

    @SelectProvider(type = ElevatorMappSql.class , method = "findNoFlag")
    List<Map<String,Object>>  findNoFlag(Map<String, Object> param);

    @Update("update elevator_text set update_flag='1' where elevator_num=#{elevatorNum}")
    void updateFlagSQL(Map<String, Object> map);

    @Insert(" insert into elevator_task (create_date) values (#{taskmap}) ")
    void task(String taskmap);

    @Delete(" delete from elevator_task ")
    void deleteTask();



    @Select("select * from elevator_task")
    List<Map<String, Object>> findTask();

    @Select("select elevator_num as elevatorNum,id,user_unit_name as userUnitName,outside_num as outsideNum from elevator_unit where party_id = #{partyId} and update_flag is null limit 500")
    List<Map<String, Object>> findElevatorUnit(String partyId);

    @Select("select * from elevator where outside_num=#{outsideNum} limit 1")
    Elevator queryByOutsideNum(String outsideNum);


    @UpdateProvider(type = ElevatorMappSql.class,method = "updateById")
    void updateById(Map<String, Object> map);

    @Update("update elevator_unit set update_flag='1' where id=#{id}")
    void updateUnitById(String id);

    @SelectProvider(type = ElevatorMappSql.class,method = "noownerElevatorQuery")
    List<ExtElevator> noownerElevatorQuery(ExtElevator elevator) throws Exception;

    @UpdateProvider(type = ElevatorMappSql.class,method = "noownerElevatorUpdate")
    int noownerElevatorUpdate(Map<String,Object> map);

    @Update(" UPDATE elevator a set a.maintenance_party_id = #{maintenancePartyId},a.used_party_id = #{usedPartyId} where a.id = #{id} ")
    void updateMainPartyIdAndPartyId(Elevator elevator);

    /**
     * 公众端接口前端通过设备编号进行查询
     * @param id
     * @return
     */
    @Select( " select a.*,e.user_name as safeUserName,b.type_name as elevatorTypeName, c.party_name as usedPartyName, c.credit_code as creditCode," +
            "d.party_name as maintenancePartyName, f.check_end_dt as checkEndDt" +
            " from elevator a " +
            "left join elevator_type b on a.elevator_type_id = b.id  " +
            "left join party c on c.id = a.used_party_id  " +
            "left join party d on d.id = a.maintenance_party_id " +
            "left join daily_inspection f on f.elevator_id=a.id " +
            "left join sys_user e on a.safe_user_id = e.id "+
            " where a.out_elevator_id=#{id} " +
            " ORDER BY f.id desc limit 1 " )
    ExtElevator publicUserElevator(String id);
    @UpdateProvider(type = ElevatorMappSql.class,method = "updateElevatorType")
    void updateElevatorType(Map<String,Object> param);
    @Update(" update elevator set elevator_type_id = #{elevatorTypeId} where elevator_num = #{elevatorNum} or outside_num = #{outsideNum} ")
    void banchUpdateElevatoeType(Elevator elevator);

    @Select("select *  from elevator_type")
    List<ElevatorType> queryElevatorType();

    @Select(" select elevator_num,outside_num,used_party_id from elevator where maintenance_party_id = #{partyId}")
    List<ExtElevator> queryElevatorByMain(String partyId);

    @Select( " select r.id as id,r.elevator_num as elevatorNum,r.outside_num as outsideNum from elevator r where r.maintenance_party_id is null OR r.maintenance_party_id ='' ")
    List<Map<String, Object>> nomainElevator();

    @Select( " select r.id as id,r.elevator_num as elevatorNum,r.outside_num as outsideNum from elevator r where r.maintenance_party_id = #{partyId} ")
    List<Map<String, Object>> hasmainElevator(String partyId);

    @Select( " select py.id,sum(1) eleNum from party py LEFT JOIN elevator er ON py.id = er.maintenance_party_id where (party_type='1' OR party_type='2') group by py.id ")
    List<Map<String, Object>> groupByElevator();

    /**
     * 查询未确认的维保工单
     * @param param
     * @return
     */
    @SelectProvider(type = ElevatorMappSql.class,method = "unconfirmedMaintenance")
    List<UnconfigMaintedVo> unconfirmedMaintenance(Map<String, Object> param);

    @Insert(" insert into unconfirmed_maintenance (elevator_num,outside_num,message,create_date,maintenance_party_id,used_party_id,safe_user_id,maintenance_user_name,maintenance_user_name2,elevator_type,work_type) values (#{elevatorNum},#{outsideNum},#{message},#{createDate},#{maintenancePartyId},#{usedPartyId},#{safeUserId},#{maintenanceUserName},#{maintenanceUserName2},#{type},#{workType}) ")
    void insertUnconfirm(Map<String, Object> insertTodo);

    @Select(" select message as 'message',id as 'id', elevator_num as 'elevatorNum' from unconfirmed_maintenance where elevator_num=#{elevatorNum} ")
    Map<String, Object> findConfirmed(String elevatorNum);
    @Delete(" delete from unconfirmed_maintenance where id=#{id}")
    void deleteConfirmed(String id);
    /**
     * 使用单位查询未确认的维保工单
     * @param param
     * @return
     */
    @SelectProvider(type = ElevatorMappSql.class,method = "needconfirmedMaintenance")
    List<Map<String, Object>> needconfirmedMaintenance(Map<String, Object> param);
    @Update(" update unconfirmed_maintenance set message='1' where elevator_num=#{elevatorNum} ")
    void updateSuccess(String elevatorNum);

    /**
     * 查询update_flag 为 1 500条
     * @return
     */
    @Select(" SELECT * FROM elevator_original where update_flag is null limit 500 ")
    List<Elevator> queryElevatorFlag();

    @Select( " select * from elevator where elevator_num=#{elevatorNum} " )
    List<Elevator> findElevatorList(String elevatorNum);

    @Update("update elevator set outside_num=#{outsideNum} where id=#{id}")
    int updateOutSideNum(@Param("id") String id,@Param("outsideNum") String outsideNum);

    @Update("update elevator_original set update_flag='1',create_by=#{date} where id=#{id}")
    void updateOriginal(@Param("id") Long id, @Param("date") String date);


    @Insert("insert into elevator ( angle, be_used_date, " +
            "      build_addr, build_party_name, building_info, " +
            "      create_company_name, drive_way, elevator_addr, " +
            "      elevator_area, elevator_building_num, elevator_city, " +
            "      elevator_model, elevator_num, elevator_photo_url, " +
            "      elevator_province, elevator_street, elevator_type_id, " +
            "      examination_party_id, examination_party_name, " +
            "      floor_station, governor_ck_date, insurance_date, " +
            "      insurance_name, insurance_num, is_stop, " +
            "      last_maintenance_time, lift_height, maint_tel, " +
            "      maintenance_party_id, maintenance_user_first, " +
            "      maintenance_user_second, next_check_date, next_halfmon_maint_date, " +
            "      next_halfyear_maint_date, next_quarterly_mainte_date, " +
            "      next_year_maint_date, outside_num, points_num, " +
            "      qr_code_url, rated_load, rescue_phone_num, " +
            "      run_speed, safe_user_id, safe_user_tel, " +
            "      serial_num, step_width, url, " +
            "      used_num, used_party_id,brand_Name,branch_office,place_type,elevator_place,"
            + "    examination_user_first,examination_user_second,inner_id,last_inspect_date,program_name,out_elevator_id,maintenance_party_credit_code)" +
            "    values ( #{angle}, #{beUsedDate}, " +
            "      #{buildAddr}, #{buildPartyName}, #{buildingInfo}, " +
            "      #{createCompanyName}, #{driveWay}, #{elevatorAddr}, " +
            "      #{elevatorArea}, #{elevatorBuildingNum}, #{elevatorCity}, " +
            "      #{elevatorModel}, #{elevatorNum}, #{elevatorPhotoUrl}, " +
            "      #{elevatorProvince}, #{elevatorStreet}, #{elevatorTypeId}, " +
            "      #{examinationPartyId}, #{examinationPartyName}, " +
            "      #{floorStation}, #{governorCkDate}, #{insuranceDate}, " +
            "      #{insuranceName}, #{insuranceNum}, #{isStop}, " +
            "      #{lastMaintenanceTime}, #{liftHeight}, #{maintTel}, " +
            "      #{maintenancePartyId}, #{maintenanceUserFirst}, " +
            "      #{maintenanceUserSecond}, #{nextCheckDate}, #{nextHalfmonMaintDate}, " +
            "      #{nextHalfyearMaintDate}, #{nextQuarterlyMainteDate}, " +
            "      #{nextYearMaintDate}, #{outsideNum}, #{pointsNum}, " +
            "      #{qrCodeUrl}, #{ratedLoad}, #{rescuePhoneNum}, " +
            "      #{runSpeed}, #{safeUserId}, #{safeUserTel}, " +
            "      #{serialNum}, #{stepWidth}, #{url}, " +
            "      #{usedNum}, #{usedPartyId},#{brandName},#{branchOffice},#{placeType},#{elevatorPlace},"
            + "    #{examinationUserFirst},#{examinationUserSecond},#{innerId},#{lastInspectDate},#{programName},#{outElevatorId},#{maintenancePartyCreditCode})")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    int addElevator(Elevator elevator);

    /**
     * 获取单位下的电梯
     * @param param
     * @return
     */
    @SelectProvider(type = ElevatorMappSql.class,method = "findEleByUnit")
    List<UnconfigMaintedVo> findEleByUnit(Map<String, Object> param);

    @SelectProvider(type = ElevatorMappSql.class,method = "getLatLngByLevel")
    List<Map<String,Object>> getLatLngByLevel(Map<String, Object> param);

    @Select(" select DISTINCT used_party_id as 'usedPartyId',py.party_name as 'usedPartyName' from elevator er LEFT JOIN party py ON py.id = er.used_party_id where er.maintenance_party_id=#{maintenancePartyId} and used_party_id is not null; ")
    List<ExtElevator> getPartyNameById(Long maintenancePartyId);

    /**
     * 电梯数据何苏持久表
     * @param list
     */
    @Insert("<script> insert into persistent_elevator (elevator_num,outside_num,serial_num, " +
            "      elevator_province, elevator_city, elevator_area, " +
            "      elevator_street, elevator_addr, elevator_model, " +
            "      elevator_type_name, maintenance_party_name, maintenance_party_credit_code, " +
            "      used_party_name, used_party_credit_code, elevator_building_num, " +
            "      create_company_name, examination_party_name, next_check_date, " +
            "      check_qualified_photo, safe_user_name, " +
            "      maintenance_user_first_name, maintenance_user_second_name, rescue_phone_num, " +
            "      is_stop, brand_name, maint_tel, " +
            "      insurance_name, insurance_date,build_addr, used_num,be_used_date, " +
            "      governor_ck_date, floor_station, " +
            "      safe_user_tel, build_party_name, rated_load, " +
            "      run_speed, angle, " +
            "      step_width, lift_height, drive_way, " +
            "      lat, lng, branch_office_name, " +
            "      elevator_place, out_elevator_id,create_date,hs_maintenance_party_id,hs_used_party_id " +
            "       )" +
            "    values " +
            "<foreach collection = 'list' item='record' separator=',' > "+
            "      ( #{record.elevatorNum},#{record.outsideNum},#{record.serialNum}, " +
            "      #{record.elevatorProvince},#{record.elevatorCity},#{record.elevatorArea}, " +
            "      #{record.elevatorStreet},#{record.elevatorAddr},#{record.elevatorModel}, " +
            "      #{record.elevatorTypeName},#{record.maintenancePartyName},#{record.maintenancePartyCreditCode}, " +
            "      #{record.usedPartyName}, #{record.usedPartyCreditCode}, #{record.elevatorBuildingNum}, " +
            "      #{record.createCompanyName}, #{record.examinationPartyName}, #{record.nextCheckDate}, " +
            "      #{record.checkQualifiedPhoto}, #{record.safeUserName}, " +
            "      #{record.maintenanceUserFirstName}, #{record.maintenanceUserSecondName}, #{record.rescuePhoneNum}, " +
            "      #{record.isStop}, #{record.brandName}, #{record.maintTel}, " +
            "      #{record.insuranceName},#{record.insuranceDate}, #{record.buildAddr},#{record.usedNum}, #{record.beUsedDate}, " +
            "      #{record.governorCkDate}, #{record.floorStation}, " +
            "      #{record.safeUserTel}, #{record.buildPartyName}, #{record.ratedLoad}, " +
            "      #{record.runSpeed}, #{record.angle}, " +
            "      #{record.stepWidth}, #{record.liftHeight}, #{record.driveWay}, " +
            "      #{record.lat}, #{record.lng}, #{record.branchOfficeName}, " +
            "      #{record.elevatorPlace}, #{record.outElevatorId}, #{record.createDate},#{record.maintenancePartyId},#{record.usedPartyId})"
            + "</foreach>"
            + "</script>")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    void interfaceAddPersistent(List<Map<String, Object>> list);

    /**
     * 电梯数据何苏临时表
     * @param list
     */
    @Insert("<script> insert into receive_hesu_elevator (elevator_num,outside_num,serial_num, " +
            "      elevator_province, elevator_city, elevator_area, " +
            "      elevator_street, elevator_addr, elevator_model, " +
            "      elevator_type_name, maintenance_party_name, maintenance_party_credit_code, " +
            "      used_party_name, used_party_credit_code, elevator_building_num, " +
            "      create_company_name, examination_party_name, next_check_date, " +
            "      check_qualified_photo, safe_user_name, " +
            "      maintenance_user_first_name, maintenance_user_second_name, rescue_phone_num, " +
            "      is_stop, brand_name, maint_tel, " +
            "      insurance_name, insurance_date,build_addr, used_num,be_used_date, " +
            "      governor_ck_date, floor_station, " +
            "      safe_user_tel, build_party_name, rated_load, " +
            "      run_speed, angle, " +
            "      step_width, lift_height, drive_way, " +
            "      lat, lng, branch_office_name, " +
            "      elevator_place, out_elevator_id,create_date,hs_maintenance_party_id,hs_used_party_id " +
            "       )" +
            "    values " +
            "<foreach collection = 'list' item='record' separator=',' > "+
            "      ( #{record.elevatorNum},#{record.outsideNum},#{record.serialNum}, " +
            "      #{record.elevatorProvince},#{record.elevatorCity},#{record.elevatorArea}, " +
            "      #{record.elevatorStreet},#{record.elevatorAddr},#{record.elevatorModel}, " +
            "      #{record.elevatorTypeName},#{record.maintenancePartyName},#{record.maintenancePartyCreditCode}, " +
            "      #{record.usedPartyName}, #{record.usedPartyCreditCode}, #{record.elevatorBuildingNum}, " +
            "      #{record.createCompanyName}, #{record.examinationPartyName}, #{record.nextCheckDate}, " +
            "      #{record.checkQualifiedPhoto}, #{record.safeUserName}, " +
            "      #{record.maintenanceUserFirstName}, #{record.maintenanceUserSecondName}, #{record.rescuePhoneNum}, " +
            "      #{record.isStop}, #{record.brandName}, #{record.maintTel}, " +
            "      #{record.insuranceName},#{record.insuranceDate}, #{record.buildAddr},#{record.usedNum}, #{record.beUsedDate}, " +
            "      #{record.governorCkDate}, #{record.floorStation}, " +
            "      #{record.safeUserTel}, #{record.buildPartyName}, #{record.ratedLoad}, " +
            "      #{record.runSpeed}, #{record.angle}, " +
            "      #{record.stepWidth}, #{record.liftHeight}, #{record.driveWay}, " +
            "      #{record.lat}, #{record.lng}, #{record.branchOfficeName}, " +
            "      #{record.elevatorPlace}, #{record.outElevatorId}, #{record.createDate},#{record.maintenancePartyId},#{record.usedPartyId})"
            + "</foreach>"
            + "</script>")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    void interfaceAddCursor(List<Map<String, Object>> list);

    /**
     * 查询持久表数据
     * @return
     */
    @Select(" SELECT id as 'id', " +
            " elevator_num AS 'elevatorNum', " +
            " outside_num AS 'outsideNum', " +
            " serial_num AS 'serialNum', " +
            " elevator_province AS 'elevatorProvince', " +
            " elevator_city AS 'elevatorCity', " +
            " elevator_area AS 'elevatorArea', " +
            " elevator_street AS 'elevatorStreet', " +
            " elevator_addr AS 'elevatorAddr', " +
            " elevator_model AS 'elevatorModel', " +
            " elevator_type_name AS 'elevatorTypeName', " +
            " maintenance_party_name AS 'maintenancePartyName', " +
            " maintenance_party_credit_code AS 'maintenancePartyCreditCode', " +
            " used_party_name AS 'usedPartyName', " +
            " used_party_credit_code AS 'usedPartyCreditCode', " +
            " elevator_building_num AS 'elevatorBuildingNum', " +
            " create_company_name AS 'createCompanyName', " +
            " examination_party_name AS 'examinationPartyName', " +
            " next_check_date AS 'nextCheckDate', " +
            " check_qualified_photo AS 'checkQualifiedPhoto', " +
            " safe_user_name AS 'safeUserName', " +
            " maintenance_user_first_name AS 'maintenanceUserFirstName', " +
            " maintenance_user_second_name AS 'maintenanceUserSecondName', " +
            " rescue_phone_num AS 'rescuePhoneNum', " +
            " is_stop AS 'isStop', " +
            " brand_name AS 'brandName', " +
            " maint_tel AS 'maintTel', " +
            " insurance_name AS 'insuranceName', " +
            " insurance_date AS 'insuranceDate', " +
            " build_addr AS 'buildAddr', " +
            " used_num AS 'usedNum', " +
            " be_used_date AS 'beUsedDate', " +
            " governor_ck_date AS 'governorCkDate', " +
            " floor_station AS 'floorStation', " +
            " safe_user_tel AS 'safeUserTel', " +
            " build_party_name AS 'buildPartyName', " +
            " rated_load AS 'ratedLoad', " +
            " run_speed AS 'runSpeed', " +
            " angle AS 'angle', " +
            " step_width AS 'stepWidth', " +
            " lift_height AS 'liftHeight', " +
            " drive_way AS 'driveWay', " +
            " lat AS 'lat', " +
            " lng AS 'lng', " +
            " branch_office_name AS 'branchOfficeName', " +
            " elevator_place AS 'elevatorPlace', " +
            " out_elevator_id AS 'outElevatorId' " +
            " FROM persistent_elevator where elevator_num is not null ORDER BY create_date ASC limit 1000 ")
    List<ReceiveHesuElevator> receiveHesuElevator();

    @Select("select elevator_num from elevator where elevator_num=#{elevatorNum} ")
    String interfaceFindDataByNum(String elevatorNum);


    @UpdateProvider(type = ElevatorMappSql.class,method = "interfaceUpdateByNum")
    int interfaceUpdateByNum(ReceiveHesuElevator hesuElevator);

    @Delete(" delete from persistent_elevator where id =#{id} ")
    void deleteReceiveHesuById(int id);

    @Insert("    insert into elevator (elevator_num,outside_num,serial_num, " +
            "      elevator_province, elevator_city, elevator_area, " +
            "      elevator_street, elevator_addr, elevator_model, " +
            "      elevator_type_name, maintenance_party_name, maintenance_party_credit_code, " +
            "      used_party_name, used_party_credit_code, elevator_building_num, " +
            "      create_company_name, examination_party_name, next_check_date, " +
            "      check_qualified_photo, safe_user_name, " +
            "      maintenance_user_first_name, maintenance_user_second_name, rescue_phone_num, " +
            "      is_stop, brand_name, maint_tel, " +
            "      insurance_name, insurance_date,build_addr, used_num,be_used_date, " +
            "      governor_ck_date, floor_station, " +
            "      safe_user_tel, build_party_name, rated_load, " +
            "      run_speed, angle, " +
            "      step_width, lift_height, drive_way, " +
            "      lat, lng, branch_office_name, " +
            "      elevator_place, out_elevator_id,create_date,elevator_type_id " +
            "       )" +
            "    values " +
            "      ( #{elevatorNum},#{outsideNum},#{serialNum}, " +
            "      #{elevatorProvince},#{elevatorCity},#{elevatorArea}, " +
            "      #{elevatorStreet},#{elevatorAddr},#{elevatorModel}, " +
            "      #{elevatorTypeName},#{maintenancePartyName},#{maintenancePartyCreditCode}, " +
            "      #{usedPartyName}, #{usedPartyCreditCode}, #{elevatorBuildingNum}, " +
            "      #{createCompanyName}, #{examinationPartyName}, #{nextCheckDate}, " +
            "      #{checkQualifiedPhoto}, #{safeUserName}, " +
            "      #{maintenanceUserFirstName}, #{maintenanceUserSecondName}, #{rescuePhoneNum}, " +
            "      #{isStop}, #{brandName}, #{maintTel}, " +
            "      #{insuranceName},#{insuranceDate}, #{buildAddr},#{usedNum}, #{beUsedDate}, " +
            "      #{governorCkDate}, #{floorStation}, " +
            "      #{safeUserTel}, #{buildPartyName}, #{ratedLoad}, " +
            "      #{runSpeed}, #{angle}, " +
            "      #{stepWidth}, #{liftHeight}, #{driveWay}, " +
            "      #{lat}, #{lng}, #{branchOfficeName}, " +
            "      #{elevatorPlace}, #{outElevatorId}, #{createDate},#{elevatorTypeId})")
    int insertIntoAdd(ReceiveHesuElevator hesuElevator);
}
